package com.wyl.mine.friends

import android.view.KeyEvent
import android.view.View
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.wyl.libbase.extend.hideKeyboard
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.binding.recyclerview.RecyclerViewDivider
import com.wyl.libbase.extend.autoWired
import com.wyl.mine.R
import com.wyl.mine.databinding.ItemLikeorfansBinding
import com.wyl.mine.databinding.LikeListActivityBinding
import io.ditclear.bindingadapter.BindingViewHolder
import io.ditclear.bindingadapter.ItemClickPresenter
import io.ditclear.bindingadapter.ItemDecorator
import io.ditclear.bindingadapter.SingleTypeAdapter
import kotlinx.android.synthetic.main.like_list_activity.*
import org.koin.android.viewmodel.ext.android.viewModel

class LikeListActivity : BindingActivity<LikeListActivityBinding>() {

    private val title by lazy { autoWired("title", "") }

    private val viewModel by viewModel<LikeListViewModel>()

    override fun getLayoutId(): Int = R.layout.like_list_activity

    override fun initView() {
        binding.vm = viewModel

        binding.titlebar.apply {
            centerTextView.text = title
            setListener { _, action, _ ->
                when (action) {
                    CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                    else -> {
                    }
                }
            }
        }

        binding.include.recyclerView.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = mAdapter
            addItemDecoration(RecyclerViewDivider(context, RecyclerViewDivider.VERTICAL))
        }


        search.setOnEditorActionListener { v, _, event: KeyEvent? ->
            if (event?.action == KeyEvent.ACTION_DOWN) {
                if (v.text.isNotEmpty()) {
                    // 搜索
                    v.text = ""
                    hideKeyboard()
                }
                return@setOnEditorActionListener true
            }
            return@setOnEditorActionListener false
        }
    }

    private val mAdapter by lazy {
        SingleTypeAdapter(this, R.layout.item_likeorfans, viewModel.dataSource)
            .apply {
                itemPresenter = object : ItemClickPresenter<Any> {
                    override fun onItemClick(v: View, item: Any) {

                    }
                }
//                itemDecorator = object : ItemDecorator {
//                    override fun decorator(
//                        holder: BindingViewHolder<ViewDataBinding>,
//                        position: Int,
//                        viewType: Int
//                    ) {
//                        val itemBinding = holder.binding as ItemLikeorfansBinding
//                        itemBinding.textView5.text = "textView5"
//                    }
//
//                }
            }
    }

    override fun loadData() {

    }
}
